package com.zerox.controller;


import com.alibaba.fastjson.JSON;
import com.zerox.domain.TableVo;
import com.zerox.pojo.sysRole;
import com.zerox.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Controller
@RequestMapping("/sysRole")
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;

    @GetMapping("/list")
    @ResponseBody
    public void sysRole(Model model, HttpServletResponse response, Integer page, Integer limit) throws IOException {

        List<sysRole> sysRoleList = sysRoleService.list((page - 1) * limit, limit);
        TableVo tableVo = new TableVo(0, 2, sysRoleList, "");
        String json = JSON.toJSONString(tableVo);
        response.getWriter().print(json);
    }

    @GetMapping("/toSysRole")
    public String toSysRole() {
        return "SysRoleList";
    }
}
